package com.wind.taobao.api.jianghu.rest
{
	import com.adobe.serialization.json.JSON;
	import com.wind.taobao.core.util.TaobaoConstants;
	import com.wind.taobao.core.webservice.TaobaoResponse;

	/**
	 * 淘江湖Response
	 * @author fxy
	 *
	 */
	public class TaobaoJianghuResponse extends TaobaoResponse
	{
		/**
		 * 淘江湖错误代码
		 */
		public var subCode:String;
		/**
		 * 淘江湖错误信息
		 */
		public var subMessage:String;

		public function TaobaoJianghuResponse(response:TaobaoResponse=null)
		{
			if (response != null)
			{
				if (this.format == "json")
				{
					var jsonRsp:Object=JSON.decode(String(response.body));
					if (jsonRsp.hasOwnProperty(TaobaoConstants.ERROR_RESPONSE))
					{
						//
						this.errorCode=jsonRsp[TaobaoConstants.ERROR_RESPONSE][TaobaoConstants.ERROR_CODE];
						this.msg=jsonRsp[TaobaoConstants.ERROR_RSP][TaobaoConstants.ERROR_MSG];
						//TODO 解析淘江湖错误代码
						this.subCode=jsonRsp[TaobaoConstants.ERROR_RESPONSE][TaobaoConstants.SUB_CODE];
						this.subMessage=jsonRsp[TaobaoConstants.ERROR_RESPONSE][TaobaoConstants.SUB_MSG];
					}
					this.format=response.format;
					this.body=jsonRsp;
					this.redirectUrl=response.redirectUrl;
				}
			}
		}

		/**
		 * 判断调用淘江湖API是否成功
		 *
		 * @return 如果成功,返回true
		 */
		public function get isSubSuccess():Boolean
		{
			return null == subCode;
		}
	}
}